<?php


namespace app\common\validate;


use think\Validate;

class MemberValidate extends Validate
{
    // 验证规则
    protected $rule = [
        'id' => 'require|number|unique:member',
        'username|用户名' => 'require|min:2|max:32|unique:member',
        'password|密码' => 'require|min:6|max:12',
        're_password|确认密码' => 'require|confirm:password',
        'new_password|新密码' => 'require|min:6|max:12',
        'nickname|昵称' => 'require|min:2|max:12|unique:member',
        'email|邮箱' => 'require|email|unique:member',
        'verify|验证码' => 'require|captcha',
    ];

    // 会员添加场景验证
    public function sceneAdd()
    {
        return $this->only(['username', 'password', 'nickname', 'email']);
    }

    // 会员编辑场景验证
    public function sceneEdit()
    {
        return $this->only(['id', 'username', 'password', 'new_password', 'nickname', 'email']);
    }

    // 会员注册场景验证
    public function sceneRegister()
    {
        return $this->only(['username', 'password', 're_password', 'nickname', 'email', 'captcha']);
    }

    // 会员登录场景验证
    public function sceneLogin()
    {
        return $this->only(['username', 'password', 'captcha'])
            ->remove('username', 'unique');
    }
}